/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

/**
 *
 * @author projetos
 */
public class FrmPrincipal extends javax.swing.JFrame {

    /**
     * Creates new form FrmPrincipal
     */
    public FrmPrincipal() {
        initComponents();
    }
    public FrmPessoas frmPss;
    Timer timer;
    ActionListener actionHei;
    ActionListener actionWid;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        pnlMenu = new javax.swing.JPanel();
        btnGerarCodigoSQL = new javax.swing.JToggleButton();
        btnAtualizarBaseDeDados = new javax.swing.JToggleButton();
        pnlAtualizarBaseDeDados = new javax.swing.JPanel();
        pnlGerarCodigoSql = new javax.swing.JPanel();
        btnPessoas = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PSQL - Main");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        pnlMenu.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnGerarCodigoSQL.setText("Gerar Código SQL");
        btnGerarCodigoSQL.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                btnGerarCodigoSQLStateChanged(evt);
            }
        });
        btnGerarCodigoSQL.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                btnGerarCodigoSQLItemStateChanged(evt);
            }
        });

        btnAtualizarBaseDeDados.setText("Atualizar Base De Dados");
        btnAtualizarBaseDeDados.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                btnAtualizarBaseDeDadosItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout pnlMenuLayout = new javax.swing.GroupLayout(pnlMenu);
        pnlMenu.setLayout(pnlMenuLayout);
        pnlMenuLayout.setHorizontalGroup(
            pnlMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btnAtualizarBaseDeDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(btnGerarCodigoSQL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlMenuLayout.setVerticalGroup(
            pnlMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMenuLayout.createSequentialGroup()
                .addComponent(btnGerarCodigoSQL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAtualizarBaseDeDados))
        );

        pnlAtualizarBaseDeDados.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout pnlAtualizarBaseDeDadosLayout = new javax.swing.GroupLayout(pnlAtualizarBaseDeDados);
        pnlAtualizarBaseDeDados.setLayout(pnlAtualizarBaseDeDadosLayout);
        pnlAtualizarBaseDeDadosLayout.setHorizontalGroup(
            pnlAtualizarBaseDeDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        pnlAtualizarBaseDeDadosLayout.setVerticalGroup(
            pnlAtualizarBaseDeDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        pnlGerarCodigoSql.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnPessoas.setText("Pessoas");
        btnPessoas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPessoasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlGerarCodigoSqlLayout = new javax.swing.GroupLayout(pnlGerarCodigoSql);
        pnlGerarCodigoSql.setLayout(pnlGerarCodigoSqlLayout);
        pnlGerarCodigoSqlLayout.setHorizontalGroup(
            pnlGerarCodigoSqlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btnPessoas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlGerarCodigoSqlLayout.setVerticalGroup(
            pnlGerarCodigoSqlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btnPessoas)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlGerarCodigoSql, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAtualizarBaseDeDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(159, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pnlMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlAtualizarBaseDeDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlGerarCodigoSql, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 241, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        // WIDTH = Largura
        // HEIGHT = Altura
        this.setSize(pnlMenu.getSize().width + 5, pnlMenu.getSize().height + 27);
        this.setResizable(false);
    }                                 

    private void btnGerarCodigoSQLStateChanged(javax.swing.event.ChangeEvent evt) {                                               
    }                                              

    private void btnGerarCodigoSQLItemStateChanged(java.awt.event.ItemEvent evt) {                                                   
        final int hei = this.getSize().height + pnlGerarCodigoSql.getSize().height + 7;
        if (btnGerarCodigoSQL.isSelected()) {
            if (btnGerarCodigoSQL.isSelected() == btnAtualizarBaseDeDados.isSelected()) {
                if (btnAtualizarBaseDeDados.isSelected()) {
                    btnAtualizarBaseDeDados.setSelected(false);
                } else {
                    btnAtualizarBaseDeDados.setSelected(true);
                }
            }
            actionHei = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (getSize().height > hei) {
                        timer.stop();
                    } else {
                        setSize(getSize().width, getSize().height + 5);
                    }
                }
            };
            timer = new Timer(25, actionHei);
            timer.start();
        } else {
            this.setSize(pnlMenu.getSize().width + 5, pnlMenu.getSize().height + 27);
            timer.stop();
        }

    }                                                  

    private void btnAtualizarBaseDeDadosItemStateChanged(java.awt.event.ItemEvent evt) {                                                         
        final int wid = this.getSize().width + pnlGerarCodigoSql.getSize().width + 7;
        if (btnAtualizarBaseDeDados.isSelected()) {
            if (btnGerarCodigoSQL.isSelected() == btnAtualizarBaseDeDados.isSelected()) {
                if (btnGerarCodigoSQL.isSelected()) {
                    btnGerarCodigoSQL.setSelected(false);
                } else {
                    btnGerarCodigoSQL.setSelected(true);
                }
            }
            actionWid = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (getSize().width > wid) {
                        timer.stop();
                    } else {
                        setSize(getSize().width + 5, getSize().height);
                    }
                }
            };
            timer = new Timer(25, actionWid);
            timer.start();
        } else {
            this.setSize(pnlMenu.getSize().width + 5, pnlMenu.getSize().height + 27);
            timer.stop();
        }
    }                                                        

    private void btnPessoasActionPerformed(java.awt.event.ActionEvent evt) {                                           
        if (frmPss == null) {
            btnPessoas.setEnabled(false);
            frmPss = new FrmPessoas();
            frmPss.setVisible(true);
        }

        ActionListener ae = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    if (!frmPss.isVisible()) {
                        btnPessoas.setEnabled(true);
                        frmPss = null;
                    }
                } catch (NullPointerException npe) {
                    btnPessoas.setEnabled(true);
                    frmPss = null;
                }
            }
        };
        new Timer(500, ae).start();
    }                                          

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JToggleButton btnAtualizarBaseDeDados;
    private javax.swing.JToggleButton btnGerarCodigoSQL;
    private javax.swing.JButton btnPessoas;
    private javax.swing.JPanel pnlAtualizarBaseDeDados;
    private javax.swing.JPanel pnlGerarCodigoSql;
    private javax.swing.JPanel pnlMenu;
    // End of variables declaration                   
}
